#ifndef __WORKER_H_
#define __WORKER_H_

#include "Thread.h"
#include "RefObj.h"
#include <string>
#include <vector>

namespace BASE{

class ITask : public RefObj{
public:
	ITask(): mId(0){}
	virtual ~ITask(){}
	void setId(int _mId){
		mId = _mId;
	}
	int getId(){
		return mId;
	}

public:
	virtual void run() = 0;
	virtual ITask* clone() = 0;

protected:
	int mId;
};

class TaskThread :public Thread,public RefObj{
public:
	TaskThread(ITask * _task, const std::string &_name);
	
	void setId(int mId);

	virtual ~TaskThread();

	void thread();
private:
	RefPtr<ITask> mTask;
	const std::string& name;
};

class Worker :public RefObj{
public:
	Worker(const std::string & name);	
	virtual ~Worker();

	bool create(ITask * _task, int num = 1);

	void shutdown();
private:
	std::string mName;
	std::vector<RefPtr<TaskThread> >	workers;
};
}

#endif
